home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 14335 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.7 KB  |  40 lines

  1. Newsgroups: cs.forum,cuhk.se.3420,comp.lang.c
  2. Path: new-news.sprintlink.net!eskimo!scs
  3. From: scs@eskimo.com (Steve Summit)
  4. Subject: Re: Help: a very segmentation fault!
  5. X-Nntp-Posting-Host: eskimo.com
  6. Message-ID: <Dpt8EF.D0r@eskimo.com>
  7. Sender: news@eskimo.com (News User Id)
  8. Organization: schmorganization
  9. References: <4ki7gu$bgc@eng_ser1.erg.cuhk.hk> <4kinqm$hnt@eng_ser1.erg.cuhk.hk>
  10. Date: Sat, 13 Apr 1996 16:56:38 GMT
  11.  
  12. In article <4kinqm$hnt@eng_ser1.erg.cuhk.hk>, khtsang@cs.cuhk.hk writes:
  13. > I'm a good man (mfchan@cs.cuhk.hk) wrote:
  14. >>    char block[82];
  15. >>    fp2 = fopen("fool", "r+b");
  16. >>    writeblock(fp2, 0, OVERFILE, block);
  17. > One more thing...  What is your platform??  There's no "r+b" mode for
  18. > fopen on unix systems...  Default mode is binary for all files.
  19.  
  20. More precisely, Unix makes no distinction between text and binary
  21. modes.  However, there's no need to remove the "b" from the mode
  22. string in fopen() calls on Unix machines.  Putting the "b" there
  23. documents your program's intentions, and makes the program
  24. portable to non-Unix machines.  All copies of fopen() that I'm
  25. aware of under Unix will quietly ignore the "b", since it makes a
  26. distinction which Unix is blissfully unaware of.  (ANSI C says
  27. that "b" is legal in an fopen mode string, so it's required to be
  28. either honored or quietly ignored, but as it happens pre-ANSI
  29. copies of fopen() under Unix typically ignored unrecognized
  30. characters at the end of fopen mode strings, too.)
  31.  
  32. The original poster's problem was probably that fopen() failed;
  33. "r+b" mode does not create the file if it does not exist.
  34. It's also possible that something down inside writeblock()
  35. (the definition of which I didn't see) was improperly written.
  36.  
  37.                     Steve Summit
  38.                     scs@eskimo.com
  39.